import { getStore, setStore } from "@/utils";
export default {
  state: {
    testState: 10,
    course_url:
      getStore({
        name: "course_url"
      }) || "",
    access_token:
      getStore({
        name: "access_token"
      }) || "",
    other_token:
    getStore({
      name: "other_token"
    }) || "",
    cityId:getStore({
      name: "cityId"
    }) || undefined,
      auth:
      getStore({
        name: "auth"
      }) || undefined,
      show_search:
      getStore({
        name: "show_search"
      }) || undefined,
      config: getStore({
        name: "config"
      }) || undefined
  },
  mutations: {
    SET_ACCESS_TOKEN: (state, access_token) => {
      state.access_token = access_token;
      setStore({
        name: "access_token",
        content: state.access_token,
        type: "session"
      });
    },
    SET_OTHER_TOKEN: (state, other_token) => {
      console.log(other_token)
      state.other_token = other_token;
      console.log(state)
      setStore({
        name: "other_token",
        content: state.other_token,
        type: "session"
      });
    },
    SET_cityId: (state, cityId) => {
      state.cityId = cityId;
      setStore({
        name: "cityId",
        content: state.cityId,
        type: false
      });
    },
    SET_COURSE_URL: (state, course_url) => {
      state.course_url = course_url;
      setStore({
        name: "course_url",
        content: state.course_url,
        type: "session"
      });
    },
    SET_AUTH: (state, auth) => {
      state.auth = auth;
      setStore({
        name: "auth",
        content: state.auth,
        type: false
      });
    },
    SHOW_SEARCH: (state, show_search) => {
      state.show_search = show_search;
      setStore({
        name: "show_search",
        content: state.show_search,
        type: false
      });
    },
    SET_CONFIG: (state, config) => {
      state.config = config;
      setStore({
        name: "config",
        content: state.config,
        type: false
      });
    },
  },
  actions: {
    // 根据用户名登录
    // userLogin({ commit }) {
    //   let params = {
    //     phone: "13333333333",
    //     password: "123456"
    //   };
    //   return new Promise((resolve, reject) => {
    //     userLogin(params)
    //       .then(res => {
    //         commit("SET_ACCESS_TOKEN", res.data.token);
    //         resolve();
    //       })
    //       .catch(error => {
    //         reject(error);
    //       });
    //   });
    // }
    // 获取系统配置 app下载链接
    async config({ commit }) {
      console.log(commit)
      // const res = await config({cityId:'330100'});
      // console.log(res)
      // if (res.status == 1) {
      //   commit('SET_CONFIG',res.data)
      // }
    }
  }
};
